package com.frxuexi.park2212.merchant

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.base.BaseActivity
import com.frxuexi.lib_base.entity.MerchantBeanItem
import com.frxuexi.lib_base.entity.ProcessingStep
import com.frxuexi.park2212.R
import com.frxuexi.park2212.databinding.ActivityMerchantAddBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/MerchantAddActivity")
@AndroidEntryPoint
class MerchantAddActivity : BaseActivity<ActivityMerchantAddBinding,MerchantViewModel>() {
    override fun initData() {
        vm.addMerchant.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
    }

    override fun initView() {
        binding.headMerAdd.apply {
            headerBack.setOnClickListener {
                finish()
            }
            headerTitle.setText("入驻申请")
            headerAdd.setImageResource(R.drawable.ic_action_ok)
            headerAdd.setOnClickListener {
                val name = binding.meraddName.text.toString()
                val user = binding.meraddUser.text.toString()
                val phone = binding.meraddPhone.text.toString()
                val date = binding.meraddDate.text.toString()
                val area = binding.meraddArea.text.toString().toInt()
                val num = binding.meraddNum.text.toString().toInt()
                val item = MerchantBeanItem(
                    area, "RZ:${vm.getDateTimeString(System.currentTimeMillis())}",
                    phone, user, emptyList(), name, 1, num, date, null,
                    arrayListOf(
                        ProcessingStep(
                            "新建",
                            null,
                            vm.getDateTime(System.currentTimeMillis())
                        )
                    ), "新建"
                )
                vm.addMerchant(item)
            }
        }

        binding.meraddIvdate.setOnClickListener {
            showDateDialog(binding.meraddDate)
        }



    }

}